<?php
class Pxy_bm_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($_POST['type'])?$_POST['type']:false;
		if(isset($xxfget['type'])){$type=$xxfget['type'];}
        if(!$type){
        	//$result=xdb::getInstance()->getarray('select realname,pname,shiqi,p.id as pid,p.atime as ptime from peixunban as p,user u where p.bzrid=u.id and u.id='.$_SESSION['id']);
        	//$bzr=xdb::getInstance()->getarray("select id,realname from user where id in (select uid from user_groupx where gid=".(gconf('web', 'bzrid')).")");
            $pid=$xxfget['pid'];
            $pname=xdb::getInstance()->getvar("select pname from peixunban where id=".$xxfget['pid']);
            $this::show('pxy_bm',compact('pname','pid'));
        }elseif ($type=="add"){
        	$array=array();
        	$array2=array();
        	$puname=$_POST["puname"];
        	$idcard=$_POST["idcard"];
        	$minzu=$_POST["minzu"];
        	$zhiwu=$_POST["zhiwu"];
        	$mphone=$_POST["mphone"];
        	$zhicheng=$_POST["zhicheng"];
        	$workunit=$_POST["workunit"];
        	$zhuanye=$_POST["zhuanye"];
        	$address=$_POST["address"];
        	$wenhua=$_POST["wenhua"];
        	$zhengshuid=$_POST["zhengshuid"];
        	$beizhu=$_POST["beizhu"];
        	$pid=$_POST["pid"];
        	$home=$_POST["home"];
        	$peixununit=$_POST["peixununit"];
        	$ptype=$_POST["ptype"];
        	$xuehao=$_POST["xuehao"];
        	$zhengzhi=$_POST["zhengzhi"];
        	$array["ptype"]=$ptype;
        	$array["home"]=$home;
        	$array["peixununit"]=$peixununit;
        	$array["puname"]=$puname;
        	$array["idcard"]=$idcard;
        	$array["minzu"]=$minzu;
        	$array["zhiwu"]=$zhiwu;
        	$array["mphone"]=$mphone;
        	$array["zhicheng"]=$zhicheng;
        	$array["workunit"]=$workunit;
        	$array["zhuanye"]=$zhuanye;
        	$array["address"]=$address;
        	$array["wenhua"]=$wenhua;
        	$array["zhengshuid"]=$zhengshuid;
        	$array["beizhu"]=$beizhu;
        	$array["pid"]=$pid;
        	$array["xuehao"]=$xuehao;
        	$array["zhengzhi"]=$zhengzhi;
        	$array2['pid']=$pid;
        	$array2['idcard']=$idcard;
        	$array3=array();
        	$array4=array();
        	$array3["xuehao"]=$xuehao;
        	$array3["zhengzhi"]=$zhengzhi;
        	$array3["ptype"]=$ptype;
        	$array3["home"]=$home;
        	$array3["peixununit"]=$peixununit;
        	$array3["puname"]=$puname;
        	$array3["zhiwu"]=$zhiwu;
        	$array3["zhicheng"]=$zhicheng;
        	$array3["idcard"]=$idcard;
        	$array3["minzu"]=$minzu;
        	$array3["mphone"]=$mphone;
        	$array3["workunit"]=$workunit;
        	$array3["zhuanye"]=$zhuanye;
        	$array3["address"]=$address;
        	$array3["zhengshuid"]=$zhengshuid;
        	$array3["wenhua"]=$wenhua;
        	$array3["beizhu"]=$beizhu;
        	$array4["idcard"]=$idcard;
        	xdb::getInstance()->indb('peixunxueyuan_ku', $array3, $array4);
        	xdb::getInstance()->indb("unit_ku", array('address'=>$workunit), array('address'=>$workunit));
        	echo xdb::getInstance()->indb('peixunxueyuan', $array, $array2);
        }elseif ($type=="updshow"){
			$result=xdb::getInstance()->getrow("select * from peixunxueyuan where id=".$xxfget['puid']);
        	$this::show('pxy_upd',compact('result'));
        }else if($type=='pic'){
                $targetPath = SERVER_ROOT.'html\\uploader\\xueyuanimg'; // 指定的保存目录
                if (!empty($_FILES)) {
                	$tempFile = $_FILES['Filedata']['tmp_name'];
                	//$aid=$_POST['id'];
                	$fileTypes = array('bmp'); // File extensions
                	$fileParts = pathinfo($_FILES['Filedata']['name']);
                	$targetFile = rtrim($targetPath,'/') . '\\' .$_POST['idcard'].'.jpg';
                 	if (in_array($fileParts['extension'],$fileTypes)) {
                 	    
                	       move_uploaded_file($tempFile,$targetFile);//保存文件到指定目录
                	       echo $_POST['idcard'].'.jpg';
                 	  
                 	}
                }
            }else if($type=='serch'){
                $idcard=$_POST['idcard'];
                $result=xdb::getInstance()->getrow("select * from peixunxueyuan_ku where idcard like '".$idcard."'");
                if($result){
                    echo json_encode($result);
                }else{
                    echo 0;
                }
            }elseif($type=="unit"){
                $str=$_POST['str'];
                $dbstr=xdb::getInstance()->getjson("select address from unit_ku where address like '$str%' limit 5","ARRAY_N");
                echo $dbstr;
            }
    }
}